package com.example.project.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.example.project.entity.OperLog;

/**
 * 操作日志 数据层
 * 
 * @author ruoyi
 */
@Mapper
public interface OperLogMapper {

	/**
	 * 新增操作日志
	 * 
	 * @param operLog 操作日志对象
	 */
	@Insert("insert into t_oper_log(title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, cost_time, oper_time) "
			+ "values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, #{costTime}, sysdate())")
	public void insertOperlog(OperLog operLog);

	/**
	 * 查询系统操作日志集合
	 * 
	 * @param operLog 操作日志对象
	 * @return 操作日志集合
	 */
	@Select("<script>select oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time, cost_time "
			+ "from t_oper_log" + "<where>"
			+ "<if test=\"operIp != null and operIp != ''\">AND oper_ip like concat('%', #{operIp}, '%')</if>"
			+ "<if test=\"title != null and title != ''\">AND title like concat('%', #{title}, '%')</if>"
			+ "<if test=\"businessType != null\">AND business_type = #{businessType}</if>"
			+ "<if test=\"businessTypes != null and businessTypes.length > 0\">AND business_type in "
			+ "<foreach collection=\"businessTypes\" item=\"businessType\" open=\"(\" separator=\",\" close=\")\">#{businessType}</foreach></if>"
			+ "<if test=\"status != null\">AND status = #{status}</if>"
			+ "<if test=\"operName != null and operName != ''\">AND oper_name like concat('%', #{operName}, '%')</if>"
			+ "<if test=\"params != null and params.beginTime != null and params.beginTime != ''\">AND oper_time &gt;= #{params.beginTime}</if>"
			+ "<if test=\"params != null and params.endTime != null and params.endTime != ''\">AND oper_time &lt;= #{params.endTime}</if>"
			+ "</where></script>")
	public List<OperLog> selectOperLogList(OperLog operLog);

	/**
	 * 批量删除系统操作日志
	 * 
	 * @param ids 需要删除的数据
	 * @return 结果
	 */
	@Delete("<script>delete from t_oper_log where oper_id in "
			+ "<foreach collection=\"array\" item=\"operId\" open=\"(\" separator=\",\" close=\")\">#{operId}</foreach></script>")
	public int deleteOperLogByIds(String[] ids);

	/**
	 * 查询操作日志详细
	 * 
	 * @param operId 操作ID
	 * @return 操作日志对象
	 */
	@Select("select oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time, cost_time "
			+ "from t_oper_log where oper_id = #{operId}")
	public OperLog selectOperLogById(Long operId);

	/**
	 * 清空操作日志
	 */
	@Update("truncate table t_oper_log")
	public void cleanOperLog();
}
